package com.mairuide.base_dict.special_dates.controller;

import com.mairuide._frame.base.BaseController;
import com.mairuide.base_dict.special_dates.dto.SpecialDatesDto;
import com.mairuide.base_dict.special_dates.pojo.SpecialDates;
import com.mairuide.base_dict.special_dates.service.SpecialDatesService;
import com.mairuide.bill.information.PersonInformationService;
import com.mairuide.entity.PageResult;
import com.mairuide.entity.Result;
import com.mairuide.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description
 * @auther 刘中华
 * @create 2019-06-04 15:02
 */
@RequestMapping("/special_dates")
@Controller
public class SpecialDatesController extends BaseController {
    @Autowired
    SpecialDatesService specialDatesService;
    //案件对象接口
    @Autowired
    PersonInformationService personInformationService;

    @RequestMapping("index")
    public String index(){
        return "/base_dict/special_dates/special_dates";
    }
    @RequestMapping("openSpecialDatesDialog")
    public String openSpecialDatesDialog(){
        return "/base_dict/special_dates/openSpecialDatesDialog";
    }
    //查询节假日
    @RequestMapping("findOneById")
    @ResponseBody
    public Result findOneById(Integer id){
        SpecialDates  specialDates = specialDatesService.findOnebyId(id);
        return new Result(true, StatusCode.OK,"保存成功" ,specialDates);
    }
    //保存特殊日期
    @RequestMapping("save")
    @ResponseBody
    public Result save(SpecialDates sd){
        try {
            specialDatesService.save(sd);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"保存失败" );
        }
        return new Result(true, StatusCode.OK,"保存成功" );
    }
    //删除特殊日期
    @RequestMapping("del")
    @ResponseBody
    public Result del(Integer id){
        specialDatesService.del(id);
        return new Result(true, StatusCode.OK,"删除成功" );
    }
    //分页查询特殊日期
    @RequestMapping("page")
    @ResponseBody
    public PageResult query(SpecialDatesDto dto){
        PageResult page = specialDatesService.findByPage(dto);
        return page;
    }
}
